package com.jingxi.portal.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jingxi.common.pojo.JingXiResult;
import com.jingxi.model.TbItem;
import com.jingxi.portal.service.ContentService;

@Controller
public class IndexController {

	@Autowired
	private ContentService contentService;

	@SuppressWarnings("unchecked")
	@RequestMapping("/index")
	public String index(Model model, HttpServletRequest request) {
		List<TbItem> newlist = new ArrayList();
		List<TbItem> hotList = new ArrayList();
		List<TbItem> clothesList = new ArrayList();
		List<TbItem> giftList = new ArrayList();
		List<TbItem> flowerList = new ArrayList();

		JingXiResult newResult = contentService.showNewList();
		if (newResult!=null && newResult.getData() != null)
			newlist = (List<TbItem>) newResult.getData();
		model.addAttribute("newList", newlist);

		JingXiResult hotResult = contentService.showHotList();
		if (hotResult!=null && hotResult.getData() != null)
			hotList = (List<TbItem>) hotResult.getData();
		model.addAttribute("hotList", hotList);

		JingXiResult clothesResult = contentService.showClothesList();
		if (clothesResult!=null && clothesResult.getData() != null)
			clothesList = (List<TbItem>) clothesResult.getData();
		model.addAttribute("clothesList", clothesList);

		JingXiResult giftResult = contentService.showGiftList();
		if (giftResult!=null && giftResult.getData() != null)
			giftList = (List<TbItem>) giftResult.getData();
		model.addAttribute("giftList", giftList);

		JingXiResult flowerResult = contentService.showFlowerList();
		if (flowerResult!=null && flowerResult.getData() != null)
			flowerList = (List<TbItem>) flowerResult.getData();
		model.addAttribute("flowerList", flowerList);

		return "index";
	}

	@RequestMapping("/item")
	public String Cart() {
		return "item_test";
	}
	
	@RequestMapping("/test")
	@ResponseBody
	public String test() {
		List<TbItem> newlist = new ArrayList();
	
		JingXiResult newResult = contentService.showNewList();
		if (newResult!=null && newResult.getData() != null)
			newlist = (List<TbItem>) newResult.getData();
		return newlist.get(0).getTitle() + newlist.get(0).getPrice();
	}
}
